<?php
namespace app\www\controller;

use app\common\controller\Common;
use think\response\Json;

class Index extends Common
{
    public function index()
    {
        $data = db('stat')->where(['create_date'=>date("Ymd",time())])->find();
        if(!$data){
            db('stat')->insert(['views'=>1,'create_date'=>date("Ymd",time())]);
        }else{
            db('stat')->where(['create_date'=>date("Ymd",time())])->setInc('views');
        }
        $data = db('attachment')->where(['type'=>1])->order('sort desc')->select();
        $top = db('attachment')->where(['type'=>2])->order('sort desc')->select();
//        var_dump($data);
        $this->assign('data',$data);
        $this->assign('top',$top);

        return view();
    }



    public function yuyue(){
        $data = input('post.');
        if(empty($data['name'])){
            return json(['status'=>false,'msg'=>'请填写姓名']);
        }
        if(empty($data['mobile'])){
            return json(['status'=>false,'msg'=>'请填写手机号码']);
        }
        if(empty($data['city'])){
            return json(['status'=>false,'msg'=>'请填写居住城市']);
        }
        $data['status'] = 1;
        $data['create_date'] = date("Ymd",time());
        $data['create_date'] = intval($data['create_date']);
        $data['create_time'] = date("Y-m-d H:i:s",time());
        $data['update_time'] = date("Y-m-d H:i:s",time());
        $data['delete_time'] = date("Y-m-d H:i:s",time());
        $count = db('member')->where(['mobile'=>$data['mobile']])->count(0);
        if($count>0){
            return json(['status'=>false,'msg'=>'您今天已经预约过了']);
        }
        if(db('member')->insert($data)){
            return json(['status'=>true,'msg'=>'预约成功,工作人员稍后将与您联系']);
        }else{
            return json(['status'=>false,'msg'=>'预约失败,请稍后再试']);
        }
    }
}